/* m_laynumber
 * 
 */
package com.simulation;

import java.util.ArrayList;
import java.util.Vector;

class TNumericalGas
{
     /* the density of gas*/
     double m_density; /* rho(a)*/
     /* specific heat capacity of gas*/
     double m_sHeatCapacity; /* Cva*/
     /* when adding pressure */
     /* Dynamic viscosity of gas */
     double m_dynamicViscosity; /* mu(s) */
     /* Mole mass of gas */
     double m_moleMassGas; /* Mg */
     /* Gas constant*/
     double m_gasConstant; /* R */
     /* intrinsic velocity of gas*/
     Vector<Double> m_velocity; /* Vs */
     /* Diffusion coefficient of water vapor in the ari of the fabric*/
     double m_diffusionCoeWaterVapor; /* Da */

     /* when adding nonlocal equilibrium*/
     /* the pressure heat capacity of vapor and dry air respctively*/
     double m_pHeatCapacityVapor; /* Cp,a*/
     double m_pHeatCapacityDryAir; /* Cp,d */
     /* thermal conductivity of gas */
     double m_thermoConductivityGas; /* Kvg*/
     /* heat exchange coefficient between gas and solid fiber*/
     double m_heatExchangeCoefficient;
     TNumericalGas(int nx){};
     //~TNumericalGas();
     void InitialValue( GasType gas){
    	 m_density=gas.Density;// 1.1614*1e-3;
         m_sHeatCapacity=gas.HeatCapacity;// 1.197;
         m_dynamicViscosity=gas.DynamicViscosity;// 1.83e-4; /* mu(s) */
         m_moleMassGas=gas.MoleMass;// 29.0; /* Mg */
         m_gasConstant=gas.GasConstant;// 8.31*1.0e7; /* R */
         m_diffusionCoeWaterVapor=gas.DiffusionCoeWaterVapor;// 0.25;
         /* nonlocal*/
         m_pHeatCapacityVapor=gas.PHeatCapacityVapor;// 2.010*0.239; /* Cp,a*/
         m_pHeatCapacityDryAir=gas.PHeatCapacityDryAir; //1.005*0.239; /* Cp,d */
         m_thermoConductivityGas=gas.ThermoConductivity;// 0.239*2.59e-4; /* Kvg*/  //revise
         m_heatExchangeCoefficient=gas.CoeHeatChange;
     };
     
     //double GetCSaturatedWaterVapor(){};
};

class TNumericalLiquidWater
{
     /* latent heat of evaporation of liquid water*/
     double m_latentHeatEvaporation; /* rada*/
     /*the heat transfer coefficient of water evporation*/
     double m_evaporationHeatCoefficient;
     /* the density of liquid water*/
     double m_density; /* rho(l)*/
     /* specific heat capacity of liquid water*/
     double m_sHeatCapacity; /* Cvl*/
     /* thermal conductivity of liquid water*/
     double m_thermoConductivity; /* Kvl*/
     /* dynamic viscosity of water*/
     double m_dynamicViscosity; /* mu(l)*/
     /* surface tension*/
     double m_surfaceTension; /*sigma*/
     /* intrinsic velocity of liquid water */
     double m_velocity; /* Vl*/
     /* Mole mass of water */
     double m_moleMassWater; /* Mw */
     /* the evaporation coefficient*/
     double m_massTransfer;
     final double LetantHeat_Evaporation_X[]={0.01,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,
             11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,
             22.0,24.0,26.0,28.0,30.0,35.0,40.0,45.0,50.0,55.0,
             60.0,65.0,70.0,75.0,80.0,85.0,90.0,95.0,100.0};
     final double LetantHeat_Evaporation_Y[]={2500.5,2498.2,2495.8,2493.4,2491.1,2488.7,2486.3,2484.0,
             2481.6,2479.3,2476.9,2474.5,2472.2,2469.8,2467.5,2465.1,
             2462.8,2460.4,2458.1,2455.7,2453.3,2448.6,2443.9,2439.2,
             2434.4,2429.7,2417.8,2405.9,2393.9,2381.9,2369.8,2357.6,
             2345.4,2333.1,2320.7,2308.1,2295.5,2282.7,2269.7,2256.6,
             };
     
     void InitialValue(LiquidType liquid){
    	//m_latentHeatEvaporation=540; /* rada*/
         m_evaporationHeatCoefficient=liquid.HeatEvaporation;
         m_density=liquid.Density;// 1.0; /* rho(l)*/
         m_sHeatCapacity=liquid.HeatCapacity;// 1.0; /* Cvl*/
         m_thermoConductivity=liquid.ThermoConductivity;// 0.239*6.0e-3; /* Kvl*/
         m_dynamicViscosity=liquid.DynamicViscosity;// 0.01003; /* mu(l)*/
         m_surfaceTension=liquid.SurfaceTension;// 31.0; /*sigma*/
         m_massTransfer=liquid.HeatEvaporation;
         /* nonlocal*/
         m_moleMassWater=liquid.MoleMass;// 18.0; /* Mw */
     };
     
     double GetLatentHeatEvaporation(double t){
    	 if ((t-273.16) < LetantHeat_Evaporation_X[0])
    	    {
    	        m_latentHeatEvaporation = 2560.0*.0239;
    	        
    	    }
    	    else if ((t-273.16) > LetantHeat_Evaporation_X[39])
    	    {
    	        m_latentHeatEvaporation = 2250.0*.0239;

    	    }
    	    else
    	    {
    	        for (int j=0;j<39;j++)
    	        {
    	            if ((t-273.16) >= LetantHeat_Evaporation_X[j] &&(t-273.16) <= LetantHeat_Evaporation_X[j+1])
    	            {
    	                m_latentHeatEvaporation = (t-273.16-LetantHeat_Evaporation_X[j+1])*LetantHeat_Evaporation_Y[j]/(LetantHeat_Evaporation_X[j]-LetantHeat_Evaporation_X[j+1])
    	                                         +(t-273.16-LetantHeat_Evaporation_X[j])*LetantHeat_Evaporation_Y[j+1]/(LetantHeat_Evaporation_X[j+1]-LetantHeat_Evaporation_X[j]);
    	                m_latentHeatEvaporation=m_latentHeatEvaporation*0.239;
    	                return m_latentHeatEvaporation;
    	            }
    	        }
    	    }
    	    return m_latentHeatEvaporation;
     };
};

class TNumericalMembrane
{
      //physical properties
     //CString Type;
     double Thickness;
     Vector<Double> WVPY ; // Y-axis for WVP curves
     Vector<Double> WVPX; //edward4
//	 vector<double> TRY ;// Y-axis for TR curves
     Vector<Double> TRX; //edward4
     double WVP, TR;

     //TNumericalMembrane();
     //TNumericalMembrane & operator=(const TNumericalMembrane &menbrane);
};

class TNumericalVirus
{
     double m_density;
     /* the deposition rate coefficient*/
     double m_coeDepositionRate;  /* K1 */
     /* The release coefficient */
     double m_coeRelease;  /* K2 */
     /* The velocity of the breathing out*/
     double m_velocityBreathOut; /* V */
     /* The maxmun velocity of the breathing out*/
     double m_maxVelocityBreathOut; /* V */
     /* The radius of virus particle*/
     double m_radiusVirusParticle; /* Rv */
     /* The ratio of area of nares to effective ventilation area of the mask */
     double m_ratioAreaNares; /* k */
     /* effective capture area coefficient of the collectors */
     double m_effectiveCoeCapture; /* ce */
     /* retention efficiency */
     double m_retentionEfficiency; /* E */
     /* Adjustable parameter*/
     double m_adjustableParameter; /* b */
     /* Critical velocity */
     double m_criticalVelocity; /* Vc */
     /* release coefficient of the virus itself*/
     double releaseCoeVirus;  /* cr */
     /* Brownian coefficient */
     double m_BrownCoe;

     void InitialValue(VirusType virus) {
    	 m_density=virus.Density;// 2.0;
         m_maxVelocityBreathOut=virus.MaxVelocityBreathOut;// 20.0; /* V */
         m_radiusVirusParticle=virus.RadiusVirusParticle;// 5.0e-6; /* Rv */
         m_ratioAreaNares=virus.RatioAreaNares;// 0.02; /* k */
         m_effectiveCoeCapture=virus.EffectiveCoeCapture;// 0.1; /* ce */
         m_retentionEfficiency=virus.RetentionEfficiency;// 0.01; /* E */
         m_adjustableParameter=virus.AdjustableParameter;// 0.01; /* b */
         m_criticalVelocity=virus.CriticalVelocity;// 0.1e-9; /* Vc */
         releaseCoeVirus=virus.ReleaseCoeVirus;// 0.3;  /* cr */
         m_BrownCoe=virus.BrownCoe;// 1.82e-6;
     };
     
     void GetVelocityBreathOut(int j) {
    	 m_velocityBreathOut=(Math.sin(3.14159*j*0.001/2.0)*m_maxVelocityBreathOut);
     };

};

class TNumericalPCM
{
     /* radius of micro-spheres*/
     double m_radius; /* Rm */
     double m_density; /* rho(m)*/
     /* thermao conductivity of liquid PCM*/
     double m_thermoLiqConductivity; /* Kml*/
     /* thermo conductivity of solid PCM */
     double m_thermoSolidConductivity; /* Kms */
     /* Latent heat of fusion of PCM */
     double m_latentHeatPCM; /* rambda(m) */
     /* heat transfer coefficient between the micro-spheres and the flows surrounding them in porous textile*/
     double m_heatTransferCoe; /* hT*/
     /* melting temperature of PCM */
     double m_meltingTemperature; /* Tp*/

     void InitialValue(PCMType pcm) {
    	 m_radius=pcm.Radius;// 5.0e-4; /* Rm */
         m_density=pcm.Density;// 0.779; /* rho(m)*/
         m_thermoLiqConductivity=pcm.K_ml;// 0.000717; /* Kml*/
         m_thermoSolidConductivity=pcm.K_ms;// 0.000956; /* Kms */
         m_latentHeatPCM=pcm.Ramda_m;// 238.76*0.239; /* rambda(m) */
         m_heatTransferCoe=pcm.h_T;// 0.01195; /* hT*/
         m_meltingTemperature=pcm.T_p; //meltingTemperature;//28.0+273.16; /* Tp*/
     };
};

class TNumericalRadiation
{
     /* stefan-Boltmann constant*/
     double m_stefanConstant;
     void InitialValue() {
    	 m_stefanConstant=0.239*5.67e-12;
     };
};

class TNumericalSelfHeating
{
     /* the heat get from the heating source in fabric*/
     double m_heatGot; /* QH1*/
     /* the heat loss from the cooling source in fabric */
     double m_heatLoss; /* QH2*/
     /* the cooling system control temperature*/
     double m_coolControlTemperature; /* QC */
     /* the heating system control temperature*/
     double m_heatControlTemperature;
     double m_heatVolume;
     double m_coolVolume;

     void InitialValue(SelfHeatType selfHeat) {
    	m_coolControlTemperature=selfHeat.CoolTemperature;// 25.0+273.16; /* QC */
        m_heatControlTemperature=selfHeat.HeatTemperature;// 27.0+273.16;
        m_heatVolume=selfHeat.HeatGot;
        m_coolVolume=selfHeat.HeatLoss;
     };
     
     void SelfHeating(double t) {
    	 if(t>m_heatControlTemperature)
    	    {
    	        m_heatLoss=m_coolVolume;//29.0+273.16; /* QH1*/
    	        m_heatGot=0;
    	    }

    	    else if(t<m_coolControlTemperature)
    	    {
    	        m_heatGot=m_heatVolume;//25.0+273.16; /* QH2*/
    	        m_heatLoss=0;
    	    }
     };
};

class TNumericalEnvironment
{
    /* the environment temperature next to inner fabric */
    double m_temperatureInner;
    /* the environment temperature next to outer fabric */
    double m_temperatureOuter;
    /* the environment relative humidity next to inner fabric */
    double m_RHInner;
    /* the environment relative humidity next to Outer fabric */
    double m_RHOuter;
    /* the environment pressure next to inner fabric */
    double m_pressureInner;
    /* the environment pressure next to outer fabric */
    double m_pressureOuter;
    /* the saturated concentration of the water vopor in the inner environment*/
    double m_cWaterVaporInner;
    /* the saturated concentration of the water vopor in the inner environment*/
    double m_cWaterVaporOuter;
    /* the virus concentration in the inner environment*/
    double m_cVirusInner;
    /* the virus concentration in the outer environment*/
    double m_cVirusOuter;
    /* the liquid water fraction in the inner and outer*/
    double m_liquidWaterInner;
    double m_liquidWaterOuter;
    /* the wind velocity */
    double m_velocityWindInner;
    double m_velocityWindOuter;

    double m_stefanBoltmanConstant;

    void InitialValue(StageType stage) {
    	m_temperatureInner=stage.InTemperature;// tInner+273.16;
        m_temperatureOuter=stage.OutTemperatrue;// tOuter+273.16;
        m_RHInner=stage.InRH;// rhInner;
        m_RHOuter=stage.OutRH;// rhOuter;
        m_pressureInner=stage.InPressure;//  1013250;
        m_pressureOuter=stage.OutPressure;// 1013250;
        m_cWaterVaporInner= TPhysicalPro.WaterVaporConcentration(m_temperatureInner)*m_RHInner;
        m_cWaterVaporOuter= TPhysicalPro.WaterVaporConcentration(m_temperatureOuter)*m_RHOuter;
        m_cVirusInner=stage.InVirus;// 0.0;
        m_cVirusOuter=stage.OutVirus;// 0.0;

        m_velocityWindInner=stage.InVelocity;// velocityWind;
        m_velocityWindOuter=stage.OutVelocity;//

        m_liquidWaterInner=stage.InWater;
        m_liquidWaterOuter=stage.OutWater;

        m_stefanBoltmanConstant=stage.RadiationConstant;
    };
};

class TNumericalGarment
{
	 TNumericalGarment() {
		 /*for(int i=0;i<m_fabricList.size();++i)
			{
				m_fabricList.set(i, null);
			}
			m_fabricList.clear();*/
		m_fabricList = new Vector<TNumericalFabric>(); 
		m_virus=null;
		m_selfHeat=null;
		m_gas=null;
		m_liquid=null;
		m_equationSolver=null;
	 };
	 //~TNumericalGarment();
     Vector<TNumericalFabric> m_fabricList;
     TNumericalVirus m_virus;
     TNumericalSelfHeating m_selfHeat;
     TNumericalGas m_gas;
     TNumericalLiquidWater m_liquid;
     double thickness;
     TEquationsSolver m_equationSolver;
};